Skip to content

Fix format_as wrapping strings in double quotes + add unit tests - #23

Draft
TonyWelte with Copilot wants to merge 2 commits into
rollingfrom
copilot/fix-issue-comment-5395360111
Draft

Fix format_as wrapping strings in double quotes + add unit tests#23
TonyWelte with Copilot wants to merge 2 commits into
rollingfrom
copilot/fix-issue-comment-5395360111

Conversation

Copilot AI commented Aug 24, 2026

Copy link
Copy Markdown

format_as was using j.dump() unconditionally, which wraps JSON string values in double quotes. This caused include path lookups to fail (e.g. "msg"/UUID.json instead of msg/UUID.json).

Changes

  • Fix format_as(const json&): use j.get<std::string>() for string values, fall back to j.dump() for all other types
  • Fix format_as(const detail::iter_impl<const json>&): delegate to the value overload via format_as(*j) for consistency
  • Add unit tests in rosidlcpp_generator_core/test/unit/ covering both overloads: string values are returned unquoted, non-string types (int, bool, null, array, object) continue to use dump() format
// Before — always dumps, wrapping strings in quotes
std::string format_as(const json& j) {
  return j.dump();  // "msg" → "\"msg\""
}

// After — unquoted for strings, dump() for everything else
std::string format_as(const json& j) {
  return j.is_string() ? j.get<std::string>() : j.dump();  // "msg" → "msg"
}

Copilot AI and others added 2 commits August 24, 2026 19:14
Co-authored-by: TonyWelte <12954392+TonyWelte@users.noreply.github.com>
Co-authored-by: TonyWelte <12954392+TonyWelte@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants